using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyCinema
{
    public partial class ManageMovieForm : Form
    {
        private Cinema cinema;
        public ManageMovieForm(Cinema _cinema)
        {
            InitializeComponent();
            cinema = _cinema;
        }

        private void ManageMovieForm_Load(object sender, EventArgs e)
        {
            RefleshMovies();

        }

        private void RefleshMovies()
        {
            lvMovies.Items.Clear();
            foreach (Movie m in cinema.Schedule.Movies.Values)
            {
                ListViewItem lvi = new ListViewItem(m.MovieName);
                lvi.SubItems.Add(m.Director);
                lvi.SubItems.Add(m.Actor);
                lvi.SubItems.Add(m.MovieType.ToString());
                lvi.SubItems.Add(Convert.ToString(m.Price));
                lvMovies.Items.Add(lvi);
            }
        }

        private void btAddMovie_Click(object sender, EventArgs e)
        {
            AddMovieForm amf = new AddMovieForm(cinema,true);
            amf.ShowDialog();

            RefleshMovies();
        }

        private void btUpdateMovie_Click(object sender, EventArgs e)
        {
            if (lvMovies.SelectedItems.Count > 0)
            {
                AddMovieForm amf = new AddMovieForm(cinema, cinema.Schedule.Movies[lvMovies.SelectedItems[0].Text]);
                amf.ShowDialog();

                RefleshMovies();
            }
        }

        private void btDeleteMovie_Click(object sender, EventArgs e)
        {
            if (lvMovies.SelectedItems.Count > 0)
            {
                cinema.Schedule.RemoveMovie(lvMovies.SelectedItems[0].Text);
                RefleshMovies();
            }
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}